home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / drdobbs / 1987 / 12 / naro / boot.c next >
Text File  |  1987-12-21  |  7KB  |  71 lines

  1. #include <stdio.h>                                                                           
  2. #include <io.h>                                                                              
  3. #include <stdlib.h>                                                                          
  4. #include <string.h>                                                                          
  5. #include <malloc.h>                                                                          
  6.                                                                                              
  7. #include "loc.h"                                                                             
  8. #include "externs.h"                                                                         
  9.                                                                                              
  10.                                                                                              
  11. void  create_bootstrap(seg_list, entry)                                                      
  12. SEG_DESCRIPTOR *seg_list ;                                                                   
  13. unsigned char  *entry ;                                                                      
  14. {                                                                                            
  15.    unsigned int   count ;                                                                    
  16.    unsigned char  *ptr ;                                                                     
  17.                                                                                              
  18.    SEG_DESCRIPTOR *p, *q ;                                                                   
  19.                                                                                              
  20.    /*                                                                                        
  21.       This function sets up a new class which contains the bootstrap                         
  22.       code to the program entry point.  The bootstrap segment is                             
  23.       always located at physical address FFFF0H is ROMable.                                  
  24.                                                                                              
  25.       The bootstrap record is appended to the load module for the                            
  26.       purpose of locate processing.                                                          
  27.    */                                                                                        
  28.                                                                                              
  29.    /* Traverse the linked list to the end */                                                 
  30.    p = seg_list ;                                                                            
  31.    while (p->next != NULL)                                                                   
  32.       p = p->next ;                                                                          
  33.                                                                                              
  34.    /* Allocate the memory for the bootstrap record */                                        
  35.    if ((q = (SEG_DESCRIPTOR *) malloc(sizeof (*p))) == NULL)  {                              
  36.       perror(__FILE__) ;                                                                     
  37.       exit(1) ;                                                                              
  38.    }                                                                                         
  39.                                                                                              
  40.    /* Append the bootstrap record to the end of the list */                                  
  41.    p->next = q ;                                                                             
  42.                                                                                              
  43.    /* Initialize the bootstrap segment descriptor */                                         
  44.    strcpy(q->name, "??BOOT") ;                                                               
  45.    strcpy(q->class, "(ABSOLUTE)") ;                                                          
  46.    q->vseg = 0xffff ;                                                                        
  47.    q->pseg = 0xffff ;                                                                        
  48.    q->offset = 0x0000 ;                                                                      
  49.    q->len = 5 ;                                                                              
  50.    q->inited = TRUE ;                                                                        
  51.    q->romable = TRUE;                                                                        
  52.    q->symbols = 0 ;                                                                          
  53.    q->symbol_list = NULL ;                                                                   
  54.    q->next = NULL ;                                                                          
  55.                                                                                              
  56.    /* Allocate RAM and build the reset vector code using a far jump */                       
  57.    ptr = malloc(q->len) ;                                                                    
  58.    *ptr = 0xEA ;                                                                             
  59.    *((unsigned char **)(ptr + 1)) = entry ;                                                  
  60.                                                                                              
  61.    /* Append the bootstrap code on tail of the load module */                                
  62.    q->position = lseek(tmp_file, 0L, SEEK_END) ;                                             
  63.    count = write(tmp_file, ptr, q->len) ;                                                    
  64.    if (count != q->len)   {                                                                  
  65.       perror(__FILE__) ;                                                                     
  66.       exit(1) ;                                                                              
  67.    }                                                                                         
  68.                                                                                              
  69.    free(ptr) ;                                                                               
  70.    return ;                                                                                  
  71. }